import pymysql
db = pymysql.connect(host="localhost",user="root" ,password="123456" ,database="test")
cursor = db.cursor()

sql = "select * from user"

try:
    cursor.execute(sql)

    result = cursor.fetchall()
    for row in result:
        id = row[0]
        username = row[1]
        password = row[2]
        gender = row[3]
        print(id,username,password,gender)
except:
    print("error!")
db.close()